package com.rabbitmq.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class RpcMessageConfig {
	/**
	 * 定义rpc队列
	 */
	public static final   String rpcQueue="rpcQueue";



	public static final String rpcExchange="rpcExchange";


	public static  final String replyQueue="replyQueue";


	//使用排他队列，客户端使用并在使用完毕后删除
	@Bean
	public Queue createRpcQueue(){
		return  new Queue(rpcQueue,false,true,false,new HashMap<>());
	}


	@Bean
	public DirectExchange requestExchange() {
		return new DirectExchange(rpcExchange, false, true);
	}

	@Bean
	public Binding bindingrpc() {
		return BindingBuilder.bind(createRpcQueue()).to(requestExchange()).with("RPC-KEY");
	}

	@Bean
	public Queue replyQueue() {
		return  new Queue(replyQueue,false,true,false);
	}

	//返回队列和交换器绑定
	@Bean
	public Binding replyBinding() {
		return BindingBuilder.bind(replyQueue()).to(requestExchange()).with("RPC-REPLY-KEY");
	}


}
